package cn.zhonghuanzhiyuan.sprc.common.mock;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @author liuzhuo
 * @描述
 * @创建时间 2018/11/5
 */
@Configuration
public class IamMockWebConfig implements WebMvcConfigurer {

    /**
     * @return 用户识别拦截器
     */
    @Bean
    public HandlerInterceptorAdapter userInterceptor() {
        return new UserMockInterceptor();
    }

    private static final String[] excludePath = {
            "/swagger-ui.html",
            "/**/*swagger*/**",
            "/**/*hystrix*/**",
            "/error",
            "/idm/as/accesstoken",
            "/idm/as/login",
            "/idm/as/logout"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterceptor()).order(-1)
                .excludePathPatterns(excludePath)
                .addPathPatterns("/**/*");
    }
}
